﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Abhiruchi_Phase1.BAL_DAL.Biometric_DAL
{
    class BioDeviceInfoDAL
    {

        static SqlConnection myCon = new SqlConnection(App.ConnectionString);
        static SqlCommand myCom = new SqlCommand();
        public static DataTable GetDeviceInfoFromDB(int pType)
        {
            LoadBasicComm();
            DataTable mydt = new DataTable();
            myCom.Parameters.AddWithValue("@PType", pType);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;

        }
        private static void LoadBasicComm()
        {
           // DataTable mydt = new DataTable();
            myCom.Parameters.Clear();
            myCom.Connection = myCon;
            myCom.CommandText = "SP_BIO_GET_SET_DeviceMaster";
            myCom.CommandType = CommandType.StoredProcedure;
            //return mydt;
        }
        public static DataTable SaveinDB(int pType, string deviceID, string deviceName, int section, string remarks,int isActive)
        {
            LoadBasicComm();
            DataTable mydt = new DataTable();
            myCom.Parameters.AddWithValue("@PType", pType);
            myCom.Parameters.AddWithValue("@DeviceID", deviceID);
            myCom.Parameters.AddWithValue("@DeviceName", deviceName);
            myCom.Parameters.AddWithValue("@SectionID", section);
            myCom.Parameters.AddWithValue("@Remarks", remarks);
            myCom.Parameters.AddWithValue("@IsActive", isActive);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
        public static DataTable GetDevice(int pType, string deviceID)
        {
            LoadBasicComm();
            DataTable mydt = new DataTable();
            myCom.Parameters.AddWithValue("@PType", pType);
            myCom.Parameters.AddWithValue("@DeviceID", deviceID);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
        public static void UpdateDeviceInfo(int pType, string deviceID, string deviceName, int section, string remarks, int isActive)
        {
            LoadBasicComm();
            myCon.Open();
            DataTable mydt = new DataTable();
            myCom.Parameters.AddWithValue("@PType", pType);
            myCom.Parameters.AddWithValue("@DeviceID", deviceID);
            myCom.Parameters.AddWithValue("@DeviceName", deviceName);
            myCom.Parameters.AddWithValue("@SectionID", section);
            myCom.Parameters.AddWithValue("@Remarks", remarks);
            myCom.Parameters.AddWithValue("@IsActive", isActive);
            myCom.ExecuteNonQuery();
            myCon.Close();
        }
    }
}
